﻿//==========================================================
// 此代码由TilverNET代码生成工具自动生成，请不要修改
// 代码生成器核心库版本号：1.2
// 作者：landy
// 联系方式：(QQ)86566178
// 创建时间：2013/10/21 18:15:45
//==========================================================

using System;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Linq;
using MySql.Data;
using Tilver.Data;
using Tilver.Data.DataPager;

namespace Tilver.Mysql.DAL.Tilverdb
{
    #region EO

    /// <summary>
    ///  《customerinfo(实体类)》
    /// </summary>
    [Serializable]
    public class CustomerinfoEO : IRowMapper<CustomerinfoEO>
    {
        protected bool _hasOriginal = false;
        protected int _cid;
        protected int _originalCid;
        protected int? _cityId;
        protected string _userName;
        protected string _phone;
        protected string _address;
        protected DateTime? _recDate;
        protected sbyte _cType;

        /// <summary>
        /// 主键是否有原始值（即数据库中保存的值），用于实体对象更新时
        /// </summary>
        public bool HasOriginal
        {
            get { return _hasOriginal; }
        }


        /// <summary>
        ///  《[主键]  [int]   自增字段》
        /// </summary>
        public int Cid
        {
            get { return _cid; }
            set { _cid = value; }
        }

        /// <summary>
        ///  《数据库中的原始主键值副本》
        /// </summary>
        public int OriginalCid
        {
            get { return _originalCid; }
            set
            {
                _hasOriginal = true;
                _originalCid = value;
            }
        }

        /// <summary>
        ///  《[外键]  [int]》
        /// </summary>
        public int? CityId
        {
            get { return _cityId; }
            set { _cityId = value; }
        }

        /// <summary>
        ///  《[字段]  [varchar]》
        /// </summary>
        public string UserName
        {
            get { return _userName; }
            set
            {
                if (value != null && value.Length > 150)
                    throw new ArgumentOutOfRangeException("Invalid value for UserName", value, value == null ? "null" : value.ToString());
                _userName = value;
            }
        }

        /// <summary>
        ///  《[字段]  [varchar]》
        /// </summary>
        public string Phone
        {
            get { return _phone; }
            set
            {
                if (value != null && value.Length > 60)
                    throw new ArgumentOutOfRangeException("Invalid value for Phone", value, value == null ? "null" : value.ToString());
                _phone = value;
            }
        }

        /// <summary>
        ///  《[字段]  [varchar]》
        /// </summary>
        public string Address
        {
            get { return _address; }
            set
            {
                if (value != null && value.Length > 300)
                    throw new ArgumentOutOfRangeException("Invalid value for Address", value, value == null ? "null" : value.ToString());
                _address = value;
            }
        }

        /// <summary>
        ///  《[字段]  [datetime]》
        /// </summary>
        public DateTime? RecDate
        {
            get { return _recDate; }
            set { _recDate = value; }
        }

        /// <summary>
        ///  《[字段]  [tinyint]》
        /// </summary>
        public sbyte CType
        {
            get { return _cType; }
            set { _cType = value; }
        }

        /// <summary>
        /// 默认构造函数
        /// </summary>
        public CustomerinfoEO()
        {
        }

        /// <summary>
        /// 自定义构造函数
        /// </summary>
        /// <param name = "cid"></param>
        /// <param name = "cityId"></param>
        /// <param name = "userName"></param>
        /// <param name = "phone"></param>
        /// <param name = "address"></param>
        /// <param name = "recDate"></param>
        /// <param name = "cType"></param>
        public CustomerinfoEO(int cid, int? cityId, string userName, string phone, string address, DateTime? recDate, sbyte cType)
        {
            _cid = cid;
            _cityId = cityId;
            _userName = userName;
            _phone = phone;
            _address = address;
            _recDate = recDate;
            _cType = cType;
        }


        /// <summary>
        /// 将结果集映射成实体对象
        /// </summary>
        /// <param name = "reader">只进结果集流</param>
        /// <return></return>
        public CustomerinfoEO MapRow(IDataReader reader)
        {
            var ret = new CustomerinfoEO();
            ret.Cid = (int)reader["Cid"];
            ret.OriginalCid = ret.Cid;
            ret.CityId = (reader["CityId"] is DBNull) ? null : (int?)reader["CityId"];
            ret.UserName = (reader["UserName"] is DBNull) ? null : (string)reader["UserName"];
            ret.Phone = (reader["Phone"] is DBNull) ? null : (string)reader["Phone"];
            ret.Address = (reader["Address"] is DBNull) ? null : (string)reader["Address"];
            ret.RecDate = (reader["RecDate"] is DBNull) ? null : (DateTime?)reader["RecDate"];
            ret.CType = (sbyte)reader["CType"];
            return ret;
        }

        /// <summary>
        /// 将结果集映射成实体对象，返回映射方法
        /// </summary>
        /// <return></return>
        public Func<IDataReader, CustomerinfoEO> GetMapper()
        {
            return MapRow;
        }


    }


    #endregion
    #region MO

    /// <summary>
    ///  《customerinfo(逻辑类)》
    /// </summary>
    public class CustomerinfoMO : DbManagerBase
    {

        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name = "routeData">路由数据</param>
        public CustomerinfoMO(object routeData = null) : base(routeData) { }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name = "connectionStringName">连接字符串名称</param>
        public CustomerinfoMO(string connectionStringName) : base(connectionStringName) { }

        #endregion

        #region 私有方法
        /// <summary>
        /// 数据库访问操作方法
        /// </summary>
        /// <param name = "sql">SQL语句</param>
        /// <return>返回数据操作对象</return>
        private DbAdoBase AdoBase(string sql)
        {
            return DataBase.CreateDbAdo(sql, CommandType.Text);
        }

        #endregion

        #region Select方法集合
        /// <summary>
        /// 按主键查询
        /// </summary>
        /// <param name = "cid"></param>
        /// <param name="tm">事务管理对象</param>
        /// <return></return>
        public CustomerinfoEO SelectByPK(int cid, TransactionManager tm = null)
        {
            var sql = new StringBuilder();
            sql.AppendFormat(@"SELECT Cid, CityId, UserName, Phone, Address, RecDate, CType FROM customerinfo WHERE Cid=@Cid ");
            return AdoBase(sql.ToString())
                            .AddInParameter("@Cid", cid, DbType.Int32, 0)
                            .ExecuteReader(tm).MapToSingle(new CustomerinfoEO().GetMapper());
        }


        /// <summary>
        /// 按字段查询
        /// </summary>
        /// <param name = "cid"></param>
        /// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
        /// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
        /// <param name="tm">事务管理对象</param>
        /// <return></return>
        public List<CustomerinfoEO> SelectByCid(int cid, int top, string sort, TransactionManager tm = null)
        {
            var sql = new StringBuilder();
            var format = new StringBuilder();
            format.Append(@"SELECT {0} Cid, CityId, UserName, Phone, Address, RecDate, CType FROM customerinfo WHERE Cid=@Cid");
            if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
            sql.AppendFormat(format.ToString(), string.Empty);
            sql.Append((top > 0) ? string.Format(" LIMIT {0} ", top) : string.Empty);
            return AdoBase(sql.ToString())
                            .AddInParameter("@Cid", cid, DbType.Int32, 0)
                            .ExecuteList(new CustomerinfoEO().GetMapper(), tm);
        }
        /// <summary>
        /// 按字段查询
        /// </summary>
        /// <param name = "cityId"></param>
        /// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
        /// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
        /// <param name="tm">事务管理对象</param>
        /// <return></return>
        public List<CustomerinfoEO> SelectByCityId(int? cityId, int top, string sort, TransactionManager tm = null)
        {
            var sql = new StringBuilder();
            var format = new StringBuilder();
            format.Append(@"SELECT {0} Cid, CityId, UserName, Phone, Address, RecDate, CType FROM customerinfo WHERE CityId=@CityId");
            if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
            sql.AppendFormat(format.ToString(), string.Empty);
            sql.Append((top > 0) ? string.Format(" LIMIT {0} ", top) : string.Empty);
            return AdoBase(sql.ToString())
                            .AddInParameter("@CityId", cityId, DbType.Int32, 0)
                            .ExecuteList(new CustomerinfoEO().GetMapper(), tm);
        }
        /// <summary>
        /// 按字段查询
        /// </summary>
        /// <param name = "userName"></param>
        /// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
        /// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
        /// <param name="tm">事务管理对象</param>
        /// <return></return>
        public List<CustomerinfoEO> SelectByUserName(string userName, int top, string sort, TransactionManager tm = null)
        {
            var sql = new StringBuilder();
            var format = new StringBuilder();
            format.Append(@"SELECT {0} Cid, CityId, UserName, Phone, Address, RecDate, CType FROM customerinfo WHERE UserName=@UserName");
            if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
            sql.AppendFormat(format.ToString(), string.Empty);
            sql.Append((top > 0) ? string.Format(" LIMIT {0} ", top) : string.Empty);
            return AdoBase(sql.ToString())
                            .AddInParameter("@UserName", userName, DbType.String, 150)
                            .ExecuteList(new CustomerinfoEO().GetMapper(), tm);
        }
        /// <summary>
        /// 按字段查询
        /// </summary>
        /// <param name = "phone"></param>
        /// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
        /// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
        /// <param name="tm">事务管理对象</param>
        /// <return></return>
        public List<CustomerinfoEO> SelectByPhone(string phone, int top, string sort, TransactionManager tm = null)
        {
            var sql = new StringBuilder();
            var format = new StringBuilder();
            format.Append(@"SELECT {0} Cid, CityId, UserName, Phone, Address, RecDate, CType FROM customerinfo WHERE Phone=@Phone");
            if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
            sql.AppendFormat(format.ToString(), string.Empty);
            sql.Append((top > 0) ? string.Format(" LIMIT {0} ", top) : string.Empty);
            return AdoBase(sql.ToString())
                            .AddInParameter("@Phone", phone, DbType.String, 60)
                            .ExecuteList(new CustomerinfoEO().GetMapper(), tm);
        }
        /// <summary>
        /// 按字段查询
        /// </summary>
        /// <param name = "address"></param>
        /// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
        /// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
        /// <param name="tm">事务管理对象</param>
        /// <return></return>
        public List<CustomerinfoEO> SelectByAddress(string address, int top, string sort, TransactionManager tm = null)
        {
            var sql = new StringBuilder();
            var format = new StringBuilder();
            format.Append(@"SELECT {0} Cid, CityId, UserName, Phone, Address, RecDate, CType FROM customerinfo WHERE Address=@Address");
            if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
            sql.AppendFormat(format.ToString(), string.Empty);
            sql.Append((top > 0) ? string.Format(" LIMIT {0} ", top) : string.Empty);
            return AdoBase(sql.ToString())
                            .AddInParameter("@Address", address, DbType.String, 300)
                            .ExecuteList(new CustomerinfoEO().GetMapper(), tm);
        }
        /// <summary>
        /// 按字段查询
        /// </summary>
        /// <param name = "recDate"></param>
        /// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
        /// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
        /// <param name="tm">事务管理对象</param>
        /// <return></return>
        public List<CustomerinfoEO> SelectByRecDate(DateTime? recDate, int top, string sort, TransactionManager tm = null)
        {
            var sql = new StringBuilder();
            var format = new StringBuilder();
            format.Append(@"SELECT {0} Cid, CityId, UserName, Phone, Address, RecDate, CType FROM customerinfo WHERE RecDate=@RecDate");
            if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
            sql.AppendFormat(format.ToString(), string.Empty);
            sql.Append((top > 0) ? string.Format(" LIMIT {0} ", top) : string.Empty);
            return AdoBase(sql.ToString())
                            .AddInParameter("@RecDate", recDate, DbType.DateTime, 0)
                            .ExecuteList(new CustomerinfoEO().GetMapper(), tm);
        }
        /// <summary>
        /// 按字段查询
        /// </summary>
        /// <param name = "cType"></param>
        /// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
        /// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
        /// <param name="tm">事务管理对象</param>
        /// <return></return>
        public List<CustomerinfoEO> SelectByCType(sbyte cType, int top, string sort, TransactionManager tm = null)
        {
            var sql = new StringBuilder();
            var format = new StringBuilder();
            format.Append(@"SELECT {0} Cid, CityId, UserName, Phone, Address, RecDate, CType FROM customerinfo WHERE CType=@CType");
            if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
            sql.AppendFormat(format.ToString(), string.Empty);
            sql.Append((top > 0) ? string.Format(" LIMIT {0} ", top) : string.Empty);
            return AdoBase(sql.ToString())
                            .AddInParameter("@CType", cType, DbType.SByte, 0)
                            .ExecuteList(new CustomerinfoEO().GetMapper(), tm);
        }

        /// <summary>
        /// 按自定义条件查询
        /// </summary>
        /// <param name = "where">自定义条件,where子句</param>
        /// <param name = "top">获取行数</param>
        /// <param name = "sort">排序表达式</param>
        /// <param name = "paras">where子句中定义的参数集合</param>
        /// <param name="tm">事务管理对象</param>
        /// <return></return>
        public List<CustomerinfoEO> Select(string where, int top, string sort, IEnumerable<DbParameter> paras, TransactionManager tm = null)
        {
            var sql = new StringBuilder();
            var format = new StringBuilder();
            format.Append(@"SELECT {0} Cid, CityId, UserName, Phone, Address, RecDate, CType FROM customerinfo ");
            if (!string.IsNullOrEmpty(where)) format.AppendFormat(" WHERE {0} ", where);
            if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
            sql.AppendFormat(format.ToString(), string.Empty);
            sql.Append((top > 0) ? string.Format(" LIMIT {0} ", top) : string.Empty);
            return AdoBase(sql.ToString())
                            .AddParameters(paras)
                            .ExecuteList(new CustomerinfoEO().GetMapper(), tm);
        }

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name = "where">条件表达式</param>
        /// <param name = "sort">排序表达式</param>
        /// <param name = "paras">传入参数</param>
        /// <param name = "pageSize">页大小</param>
        /// <param name = "pageIndex">页码</param>
        /// <param name = "recordCount">总记录数，由于计算总记录数影响数据库性能，只有小于或等于0的情况下才返回总记录数</param>
        /// <return>分页数据</return>
        public List<CustomerinfoEO> SelectPager(string where, string sort, IList<DbParameter> paras, long pageSize, long pageIndex, ref long recordCount)
        {
            var sql = new StringBuilder();
            sql.AppendFormat(@"SELECT Cid, CityId, UserName, Phone, Address, RecDate, CType FROM customerinfo");
            if (!string.IsNullOrEmpty(where)) sql.AppendFormat(" WHERE {0} ", where);
            if (!string.IsNullOrEmpty(sort)) sql.AppendFormat(" ORDER BY {0} ", sort);
            var pager = this.DataBase.CreatePager(sql.ToString(), pageSize, "Cid");
            pager.AddParameters(paras);
            if (recordCount <= 0)
            {
                recordCount = pager.GetRecordCount();
            }
            return pager.GetPageData(pageIndex).MapToList(new CustomerinfoEO().GetMapper());
        }

        #endregion

        #region Insert方法集合
        /// <summary>
        /// 插入数据，有自增列时，item中自增字段为新增值，否则，返回影响的行数
        /// </summary>
        /// <param name="tm">事务管理对象</param>
        /// <param name = "item">要插入的实体对象</param>
        /// <return></return>
        public int Insert(CustomerinfoEO item, TransactionManager tm = null)
        {
            const string sql = @"INSERT INTO customerinfo (CityId, UserName, Phone, Address, RecDate, CType) VALUES (@CityId, @UserName, @Phone, @Address, @RecDate, @CType) ;SELECT LAST_INSERT_ID();";
            item.Cid = int.Parse(AdoBase(sql)
                                                .AddInParameter("@CityId", item.CityId.HasValue ? (object)item.CityId.Value : DBNull.Value, DbType.Int32, 0)
                                                .AddInParameter("@UserName", item.UserName != null ? (object)item.UserName : DBNull.Value, DbType.String, 150)
                                                .AddInParameter("@Phone", item.Phone != null ? (object)item.Phone : DBNull.Value, DbType.String, 60)
                                                .AddInParameter("@Address", item.Address != null ? (object)item.Address : DBNull.Value, DbType.String, 300)
                                                .AddInParameter("@RecDate", item.RecDate.HasValue ? (object)item.RecDate.Value : DBNull.Value, DbType.DateTime, 0)
                                                .AddInParameter("@CType", item.CType, DbType.SByte, 0)
                                                .ExecuteScalar(tm).ToString());
            return 1;
        }
        #endregion

        #region Update方法集合
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name = "item">要更新的实体对象</param>
        /// <param name = "tm">事务管理对象</param>
        /// <return></return>
        public int Update(CustomerinfoEO item, TransactionManager tm = null)
        {
            const string sql = @"UPDATE customerinfo SET CityId=@CityId, UserName=@UserName, Phone=@Phone, Address=@Address, RecDate=@RecDate, CType=@CType WHERE Cid=@OriginalCid";
            return AdoBase(sql)
                            .AddInParameter("@OriginalCid", (item.HasOriginal) ? item.OriginalCid : item.Cid, DbType.Int32, 0)
                            .AddInParameter("@CityId", item.CityId.HasValue ? (object)item.CityId.Value : DBNull.Value, DbType.Int32, 0)
                            .AddInParameter("@UserName", item.UserName != null ? (object)item.UserName : DBNull.Value, DbType.String, 150)
                            .AddInParameter("@Phone", item.Phone != null ? (object)item.Phone : DBNull.Value, DbType.String, 60)
                            .AddInParameter("@Address", item.Address != null ? (object)item.Address : DBNull.Value, DbType.String, 300)
                            .AddInParameter("@RecDate", item.RecDate.HasValue ? (object)item.RecDate.Value : DBNull.Value, DbType.DateTime, 0)
                            .AddInParameter("@CType", item.CType, DbType.SByte, 0)
                            .ExecuteNonQuery(tm);
        }
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name = "cid"></param>
        /// <param name = "cityId"></param>
        /// <return></return>
        public virtual int UpdateCityId(int cid, int? cityId)
        {
            return UpdateCityId(cid, cityId, null);
        }

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name = "tm">事务管理对象</param>
        /// <param name = "cid"></param>
        /// <param name = "cityId"></param>
        /// <return></return>
        public virtual int UpdateCityId(int cid, int? cityId, TransactionManager tm = null)
        {
            const string sql = @"UPDATE customerinfo SET CityId=@CityId  WHERE Cid=@Cid";
            return AdoBase(sql)
                            .AddInParameter("@CityId", cityId.HasValue ? (object)cityId.Value : DBNull.Value, DbType.Int32, 0)
                            .AddInParameter("@Cid", cid, DbType.Int32, 0)
                            .ExecuteNonQuery(tm);
        }

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name = "cid"></param>
        /// <param name = "userName"></param>
        /// <return></return>
        public virtual int UpdateUserName(int cid, string userName)
        {
            return UpdateUserName(cid, userName, null);
        }

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name = "tm">事务管理对象</param>
        /// <param name = "cid"></param>
        /// <param name = "userName"></param>
        /// <return></return>
        public virtual int UpdateUserName(int cid, string userName, TransactionManager tm = null)
        {
            const string sql = @"UPDATE customerinfo SET UserName=@UserName  WHERE Cid=@Cid";
            return AdoBase(sql)
                            .AddInParameter("@UserName", userName != null ? (object)userName : DBNull.Value, DbType.String, 150)
                            .AddInParameter("@Cid", cid, DbType.Int32, 0)
                            .ExecuteNonQuery(tm);
        }

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name = "cid"></param>
        /// <param name = "phone"></param>
        /// <return></return>
        public virtual int UpdatePhone(int cid, string phone)
        {
            return UpdatePhone(cid, phone, null);
        }

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name = "tm">事务管理对象</param>
        /// <param name = "cid"></param>
        /// <param name = "phone"></param>
        /// <return></return>
        public virtual int UpdatePhone(int cid, string phone, TransactionManager tm = null)
        {
            const string sql = @"UPDATE customerinfo SET Phone=@Phone  WHERE Cid=@Cid";
            return AdoBase(sql)
                            .AddInParameter("@Phone", phone != null ? (object)phone : DBNull.Value, DbType.String, 60)
                            .AddInParameter("@Cid", cid, DbType.Int32, 0)
                            .ExecuteNonQuery(tm);
        }

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name = "cid"></param>
        /// <param name = "address"></param>
        /// <return></return>
        public virtual int UpdateAddress(int cid, string address)
        {
            return UpdateAddress(cid, address, null);
        }

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name = "tm">事务管理对象</param>
        /// <param name = "cid"></param>
        /// <param name = "address"></param>
        /// <return></return>
        public virtual int UpdateAddress(int cid, string address, TransactionManager tm = null)
        {
            const string sql = @"UPDATE customerinfo SET Address=@Address  WHERE Cid=@Cid";
            return AdoBase(sql)
                            .AddInParameter("@Address", address != null ? (object)address : DBNull.Value, DbType.String, 300)
                            .AddInParameter("@Cid", cid, DbType.Int32, 0)
                            .ExecuteNonQuery(tm);
        }

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name = "cid"></param>
        /// <param name = "recDate"></param>
        /// <return></return>
        public virtual int UpdateRecDate(int cid, DateTime? recDate)
        {
            return UpdateRecDate(cid, recDate, null);
        }

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name = "tm">事务管理对象</param>
        /// <param name = "cid"></param>
        /// <param name = "recDate"></param>
        /// <return></return>
        public virtual int UpdateRecDate(int cid, DateTime? recDate, TransactionManager tm = null)
        {
            const string sql = @"UPDATE customerinfo SET RecDate=@RecDate  WHERE Cid=@Cid";
            return AdoBase(sql)
                            .AddInParameter("@RecDate", recDate.HasValue ? (object)recDate.Value : DBNull.Value, DbType.DateTime, 0)
                            .AddInParameter("@Cid", cid, DbType.Int32, 0)
                            .ExecuteNonQuery(tm);
        }

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name = "cid"></param>
        /// <param name = "cType"></param>
        /// <return></return>
        public virtual int UpdateCType(int cid, sbyte cType)
        {
            return UpdateCType(cid, cType, null);
        }

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name = "tm">事务管理对象</param>
        /// <param name = "cid"></param>
        /// <param name = "cType"></param>
        /// <return></return>
        public virtual int UpdateCType(int cid, sbyte cType, TransactionManager tm = null)
        {
            const string sql = @"UPDATE customerinfo SET CType=@CType  WHERE Cid=@Cid";
            return AdoBase(sql)
                            .AddInParameter("@CType", cType, DbType.SByte, 0)
                            .AddInParameter("@Cid", cid, DbType.Int32, 0)
                            .ExecuteNonQuery(tm);
        }

        /// <summary>
        /// 按自定义条件更新数据
        /// </summary>
        /// <param name = "set">更新列</param>
        /// <param name = "where">更新条件</param>
        /// <param name = "paras">参数集合</param>
        /// <param name="tm">事务管理对象</param>
        /// <return></return>
        public int Update(string set, string where, IEnumerable<DbParameter> paras, TransactionManager tm = null)
        {
            if (string.IsNullOrEmpty(set)) throw new ArgumentNullException("set");
            var sql = string.Format(@"UPDATE customerinfo SET {0} {1}", set, (string.IsNullOrEmpty(where) ? string.Empty : " WHERE " + where));
            return AdoBase(sql)
                            .AddParameters(paras)
                            .ExecuteNonQuery(tm);
        }
        #endregion

        #region Delete方法集合
        /// <summary>
        /// 按主键删除
        /// </summary>
        /// <param name="tm">事务管理对象</param>
        /// <param name = "cid"></param>
        public int DeleteByPK(int cid, TransactionManager tm = null)
        {
            const string sql = @"DELETE FROM customerinfo WHERE Cid=@Cid";
            return AdoBase(sql)
                            .AddInParameter("@Cid", cid, DbType.Int32, 0)
                            .ExecuteNonQuery(tm);
        }
        /// <summary>
        /// 按外键删除
        /// </summary>
        /// <param name="tm">事务管理对象</param>
        /// <param name = "cityId"></param>
        public int DeleteByCityId(int? cityId, TransactionManager tm = null)
        {
            const string sql = @"DELETE FROM customerinfo WHERE CityId=@CityId";
            return AdoBase(sql)
                            .AddInParameter("@CityId", cityId.HasValue ? (object)cityId.Value : DBNull.Value, DbType.Int32, 0)
                            .ExecuteNonQuery(tm);
        }
        /// <summary>
        /// 按字段删除
        /// </summary>
        /// <param name="tm">事务管理对象</param>
        /// <param name = "userName"></param>
        public int DeleteByUserName(string userName, TransactionManager tm = null)
        {
            const string sql = @"DELETE FROM customerinfo WHERE UserName=@UserName";
            return AdoBase(sql)
                            .AddInParameter("@UserName", userName != null ? (object)userName : DBNull.Value, DbType.String, 150)
                            .ExecuteNonQuery(tm);
        }
        /// <summary>
        /// 按字段删除
        /// </summary>
        /// <param name="tm">事务管理对象</param>
        /// <param name = "phone"></param>
        public int DeleteByPhone(string phone, TransactionManager tm = null)
        {
            const string sql = @"DELETE FROM customerinfo WHERE Phone=@Phone";
            return AdoBase(sql)
                            .AddInParameter("@Phone", phone != null ? (object)phone : DBNull.Value, DbType.String, 60)
                            .ExecuteNonQuery(tm);
        }
        /// <summary>
        /// 按字段删除
        /// </summary>
        /// <param name="tm">事务管理对象</param>
        /// <param name = "address"></param>
        public int DeleteByAddress(string address, TransactionManager tm = null)
        {
            const string sql = @"DELETE FROM customerinfo WHERE Address=@Address";
            return AdoBase(sql)
                            .AddInParameter("@Address", address != null ? (object)address : DBNull.Value, DbType.String, 300)
                            .ExecuteNonQuery(tm);
        }
        /// <summary>
        /// 按字段删除
        /// </summary>
        /// <param name="tm">事务管理对象</param>
        /// <param name = "recDate"></param>
        public int DeleteByRecDate(DateTime? recDate, TransactionManager tm = null)
        {
            const string sql = @"DELETE FROM customerinfo WHERE RecDate=@RecDate";
            return AdoBase(sql)
                            .AddInParameter("@RecDate", recDate.HasValue ? (object)recDate.Value : DBNull.Value, DbType.DateTime, 0)
                            .ExecuteNonQuery(tm);
        }
        /// <summary>
        /// 按字段删除
        /// </summary>
        /// <param name="tm">事务管理对象</param>
        /// <param name = "cType"></param>
        public int DeleteByCType(sbyte cType, TransactionManager tm = null)
        {
            const string sql = @"DELETE FROM customerinfo WHERE CType=@CType";
            return AdoBase(sql)
                            .AddInParameter("@CType", cType, DbType.SByte, 0)
                            .ExecuteNonQuery(tm);
        }
        /// <summary>
        /// 删除指定条件的记录
        /// </summary>
        /// <param name = "whereClause">自定义删除条件，where子句。如：id=1 and name='aaa'</param>
        /// <param name = "paras">where子句中定义的参数集合</param>
        /// <param name="tm">事务管理对象</param>
        /// <return></return>
        public int Delete(string whereClause, IEnumerable<DbParameter> paras, TransactionManager tm = null)
        {
            var sql = string.Format(@"DELETE FROM customerinfo {0}", (string.IsNullOrEmpty(whereClause) ? string.Empty : " WHERE " + whereClause));
            return AdoBase(sql)
                            .AddParameters(paras)
                            .ExecuteNonQuery(tm);
        }
        #endregion

        #region  自定义方法集合
        #endregion

    }


    #endregion
}
